package com.itheima.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class RunTimeMonitorAdvice {
    @Pointcut("execution(* com.itheima.service.*Service.pt*(..))")
    private void pt(){}
    @Around("pt()")
    public Object runtimeMonitor(ProceedingJoinPoint pjb) throws Throwable{
        Signature signature = pjb.getSignature();
        String targetClass = signature.getDeclaringTypeName();
        String name = signature.getName();
        long endTime = System.currentTimeMillis();
        long beginTime = System.currentTimeMillis();
        Object ret = pjb.proceed(pjb.getArgs());
        System.out.println(targetClass+"中"+name+"运行时长"+(endTime-beginTime)+"ms");
        return ret;
    }
}
